﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using IntroduceCompany.Singleton;
using IntroduceCompany.Models;
using IntroduceCompany.Util;

namespace IntroduceCompany.Controllers
{
    [HandleError]
    [CheckModule(ConstantClass.Backend_Feedback_MenuID)]
    public class FeedbackController : Controller
    {
        #region BackEnd_Feedback

        [Authorize(Roles = ConstantClass.autFeedback)]
        public ActionResult Backend_FeedbackList()
        {
            return View("/Views/Backend/Feedback/FeedbackList.aspx", DataSingleton.GetFeedbackModels().GetAllFeedback());
        }

        [Authorize(Roles = ConstantClass.autFeedback)]
        public ActionResult ChangeFeebackIsAnswerStatus(int feedbackID)
        {
            if (ModelState.IsValid)
            {
                DataSingleton.GetFeedbackModels().ChangeFeebackIsAnswerStatus(feedbackID);
            }
            return RedirectToAction("Backend_FeedbackList", "Feedback");
        }

        [Authorize(Roles = ConstantClass.autFeedback)]
        public ActionResult FeedbackDetail(int feedbackID)
        {
            return View("/Views/Backend/Feedback/FeedbackDetail.aspx", DataSingleton.GetFeedbackModels().GetOneFeedback(feedbackID));
        }

        #endregion

///////////////////////////////////////////////////////////////////////////////////////
        #region FrontEnd_Feedback

        public ActionResult Frontend_FeedbackCreate()
        {
            return View("/Views/FrontEnd/Feedback/FeedbackCreate.aspx");
        }

        [HttpPost, ValidateInput(false), ValidateAntiForgeryToken(Salt = AntiKey.EditSalt)]
        public ActionResult Frontend_FeedbackCreate(FeedbackCreateModel obj_Feedback)
        {
            if (ModelState.IsValid)
            {
                var isValidCaptchaValue = CaptchaController.IsValidCaptchaValue(obj_Feedback.CaptchaValue);
                if (isValidCaptchaValue)
                {
                    DataSingleton.GetFeedbackModels().CreateFeedback(obj_Feedback);
                    ModelState.Clear();
                    ModelState.AddModelError("Notice", IntroduceCompany.Resources.Resx.FeedbackCreate_Msg_Success);
                }
                else
                {
                    ModelState.AddModelError("FeedbackCreate_ValidateString_Captcha", IntroduceCompany.Resources.Resx.FeedbackCreate_ValidateString_Captcha);
                }
            }
            return View("/Views/FrontEnd/Feedback/FeedbackCreate.aspx");
        }

        #endregion
    }
}
